window._normal = (url, data, method) => {
    url= ""+url
    return new Promise(function (resolve, reject) {
        let XHR = new XMLHttpRequest();
        if (method === "GET" || method === "DELETE") {
            url = url + "?";
            for (let i in data) {
                url += `${i}=${data[i]}&`;
            }
        }
        XHR.open(method, url, true);
        XHR.setRequestHeader("Content-Type", "application/json");
        XHR.onreadystatechange = function () {
            if (XHR.readyState === 4) {
                if (XHR.status === 200) {
                    try {
                        let response = JSON.parse(XHR.responseText);
                        resolve(response);
                    } catch (e) {
                        reject(e);
                    }
                } else {
                    reject(new Error(XHR.statusText));
                }
            }
        };
        XHR.send(JSON.stringify(data));
    })
}

window.get =  (url, data) => {
    return _normal(url, data, "GET")
}

window.post =  (url, data) => {
    return _normal(url, data, "POST")
}

window.delete =  (url, data) => {
    return _normal(url, data, "DELETE")
}

window.put =  (url, data) => {
    return _normal(url, data, "PUT")
}